package com.shutong.springboot;

import com.sun.corba.se.spi.activation.LocatorPackage.ServerLocation;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

public class ShuTongImportSelect implements DeferredImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        // spi 技术，加载实现了AutoConfiguration 的所有子类
        // ServiceLoader.load 会读取 META-INF\services\com.shutong.springboot.AutoConfiguration的配置文件
        // 然后加载配置文件中加载的类
        ServiceLoader<AutoConfiguration> loader = ServiceLoader.load(AutoConfiguration.class);
        List<String> list  = new ArrayList<>();
        for (AutoConfiguration autoConfiguration : loader) {
            list.add(autoConfiguration.getClass().getName());
        }

        return list.toArray(new String[0]);



    }
}
